<template>
  <div
    v-loading="loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)">
    <!--搜索栏-->
    <common-list-search-bar
      ref="commonListSearchBar"
      :field-arr="searchSittingArray"
      :search-list="searchList">
      <template slot="actButton">
      </template>
    </common-list-search-bar>
    <common-list-table
      ref="myCommonListTable"
      :sitting="listTableSitting"
      :search-list="searchList">
    </common-list-table>
  </div>
</template>

<script>


import CreateSysUserDialog from '../Dialog/CreateSysUserDialog'

export default {
  name: 'UserLoginLogPage',
  components: {},
  props: {
    userIdParams: Number,
    userTypeParams: String,
  },
  mounted () {
    // this.$refs.myCommonListTable.setListData(DemoData.SysUser.list)
    this.searchList()
  },
  data: function () {
    return {
      loading: false,
      // 搜索栏配置项
      searchSittingArray: this.getFieldArr(),
      listTableSitting: {
        modelName: '登录日志',
        fieldArr: this.getFieldArr(),
        tableHeight: this.getTableHeight(),
        page: 1,
        pageSize: 20,
        actColumnWidth: -1,
        defaultSort: {
          // prop:'username',
          // order:'descending',
        }
      }
    }
  },
  methods: {
    getFieldArr: function () {
      let $this=this
      var fieldArr=Object.assign(DemoData.UserLoginLog.field)
      fieldArr.forEach(function (value, index) {
        if (value.field === 'username'){
          if ($this.$props.userIdParams > 0) {
            fieldArr[index].isSearch = false
          }else {
            fieldArr[index].isSearch = true
          }
        }
      })
      return fieldArr
    },
    getTableHeight: function () {
      var height = this.getWinSize().height - 225
      if (this.$props.userIdParams) {
        return 500
      }
      return height > 500 ? height : 500
    },
    // 初始化查询
    searchList: function () {
      // 表格列表,查询参数
      var listTableForm = this.$refs.myCommonListTable.formData

      // 搜索栏,查询参数
      var searchBarForm = this.$refs.commonListSearchBar.getFormData()

      var form = Object.assign({}, listTableForm, searchBarForm)
      if (this.$props.userIdParams) {
        form.userId = this.$props.userIdParams
      } else {
        delete form.userId
      }
      // 如果有默认排序 && 默认排序数据未设置,就进行查询请求(默认排序设置会触发查询)
      if (this.listTableSitting.defaultSort && this.listTableSitting.defaultSort.prop && this.$refs.myCommonListTable.formData.sortOrder === '') {
        return ''
      } else {

      }
      let $this = this

      $this.loading = true
      $this.MyRequest($this.ApiDoNameShop + 'User/getLoginLogList', form, function (data) {
        $this.$refs.myCommonListTable.setListData(data)
        $this.loading = false
        $this.$forceUpdate()
      })
      // console.log('全部,查询参数',form)
    },
  }
}
</script>

<style scoped>

</style>
